from spire.xls import *
from spire.xls.common import *
import os

file_dir = r'D:\Desktop\exceltest\部门'

all_files = os.listdir(file_dir)
xlsx_files = list(filter(lambda name: name.endswith('.xlsx'),all_files))

for file_name in xlsx_files:
    xlsx_file_path =rf'{file_dir}\{file_name}'
    xls_file_path = rf'{file_dir}\{file_name.split(".")[0]}.xls'
    workbook = Workbook()
    workbook.LoadFromFile(xlsx_file_path)
    workbook.SaveToFile(xls_file_path, ExcelVersion.Version97to2003)
    workbook.Dispose()



